#coding:utf8
import struct, os 
import time
 
base_path = os.path.normpath(r'/apps/data/vipdoc') 

FORMAT = 'hhfffffii' 
        
def quote_lc5(code,market='sh'): 
    path = r'%s/%s/fzline/%s%s.lc5'%(base_path, market, market,code) 
    file = open(path,'rb')
    
    size = struct.calcsize(FORMAT)
    while True:
        buf = file.read(size)
        if not buf: break
        item = struct.unpack(FORMAT, buf)
        print item 
        
def trans_lc5(path, host='172.24.180.42'):
    import os, redis
    r = redis.Redis(host=host)
    
    size = struct.calcsize(FORMAT)
    for filename in os.listdir(path):
        key = filename
        file = open(os.path.join(path,filename),'rb')
        del r[key]
        values = []
        while True:
            buf = file.read(size)
            if not buf: break
            item = struct.unpack(FORMAT, buf) 
            values.append(item)
        
        r.lpush(key, *values)
        
        print '%s completed'%key  
     
quote_lc5('600256')